<?php
return [
    'module' => [
        'name' => 'admin',
        'title' => '管理员管理',
        'table' => 'admins',
    ],
    
    'fields' => [
        'id' => [
            'type' => 'int',
            'length' => 11,
            'comment' => '管理员ID',
            'primary' => true,
            'auto_increment' => true,
            'nullable' => false,
            'required' => true,
        ],
        'username' => [
            'type' => 'varchar',
            'length' => 50,
            'comment' => '用户名',
            'required' => true,
            'nullable' => false,
            'rules' => 'required|unique:admins',
        ],
        'password' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '密码',
            'required' => true,
            'nullable' => false,
            'hidden' => true,
        ],
        'real_name' => [
            'type' => 'varchar',
            'length' => 50,
            'comment' => '真实姓名',
            'required' => false,
            'nullable' => true,
        ],
        'avatar' => [
            'type' => 'varchar',
            'length' => 255,
            'comment' => '头像',
            'required' => false,
            'nullable' => true,
        ],
        'email' => [
            'type' => 'varchar',
            'length' => 100,
            'comment' => '邮箱',
            'required' => true,
            'nullable' => false,
            'rules' => 'required|email|unique:admins',
        ],
        'mobile' => [
            'type' => 'varchar',
            'length' => 20,
            'comment' => '手机号',
            'required' => false,
            'nullable' => true,
        ],
        'last_login_ip' => [
            'type' => 'varchar',
            'length' => 45,
            'comment' => '最后登录IP',
            'required' => false,
            'nullable' => true,
        ],
        'last_login_time' => [
            'type' => 'timestamp',
            'comment' => '最后登录时间',
            'required' => false,
            'nullable' => true,
        ],
        'status' => [
            'type' => 'tinyint',
            'length' => 1,
            'comment' => '状态',
            'default' => 1,
            'options' => [
                0 => '禁用',
                1 => '启用'
            ],
        ],
        'created_at' => [
            'type' => 'timestamp',
            'comment' => '创建时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true
        ],
        'updated_at' => [
            'type' => 'timestamp',
            'comment' => '更新时间',
            'nullable' => false,
            'default' => 'CURRENT_TIMESTAMP',
            'raw_default' => true,
            'extra' => 'ON UPDATE CURRENT_TIMESTAMP'
        ],
    ],
    
    'relations' => [
        'roles' => [
            'type' => 'belongsToMany',
            'model' => 'AdminRole',
            'table' => 'admin_role_users',
            'foreign_key' => 'admin_id',
            'other_key' => 'role_id',
        ],
    ],
    
    'queries' => [
        'username' => ['like', '%?%'],
        'real_name' => ['like', '%?%'],
        'email' => ['like', '%?%'],
        'mobile' => ['like', '%?%'],
        'status' => ['=', '?'],
    ],
]; 